package com.ccxe.manage.service;

import javax.servlet.http.HttpServletRequest;

import com.ccxe.manage.service.page.bean.PageBean;



/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * @author LiXiaoChuan
 * Date: 2010-4-22 下午03:08:25
 */
public class BankBaseBusiness {

	/**
	 * 分页处理
	 * @param request
	 */
	protected void dealPara(HttpServletRequest request, PageBean pagebean) {
		int iData = 0;
		int iPage = 0;
		if (request.getParameter("nowPage") != null) {
			iPage = Integer.parseInt(request.getParameter("nowPage"));
		} else {
			iPage = 1 ;
		}
		if (request.getParameter("showData") != null) {
			iData = Integer.parseInt(request.getParameter("showData"));
		} else {
//			iData = 10 ;
			iData = pagebean.getShowData();
		}

		if (iData > pagebean.getTotalData())
			pagebean.setShowData(pagebean.getTotalData());
		else
			pagebean.setShowData(iData);
			pagebean.setPageShowData(iData);
		if (iPage > pagebean.computeTotalPage())
			pagebean.setNowPage(pagebean.getTotalPage());
		else
			pagebean.setNowPage(iPage);
	}
	
	/*
	 * 分页处理
	 * Add by panqiqiang 2010.6.30
	 */
	protected void dealPara(int nowPage, int showData, int totalData ,PageBean pagebean,String serveletPath){
		
		int iPage = nowPage;
		int iData = showData;
		
		pagebean.setServletUrl(serveletPath);
		//设置数据的总条数
		pagebean.setTotalData(totalData);
		//设置显示的数据条数
		if (iData > totalData)
			pagebean.setShowData(totalData);
		else
			pagebean.setShowData(iData);
		//设置当前显示的数据
		pagebean.setPageShowData(iData);
		//设置总页面数
		pagebean.setTotalPage(pagebean.computeTotalPage());
		//设置当前显示的页面NUM
		if (iPage > pagebean.computeTotalPage())
			pagebean.setNowPage(pagebean.getTotalPage());
		else
			pagebean.setNowPage(iPage);
	}
	
	/**
	 * 获取路径URL
	 * @param request
	 * @return
	 */
	public String getServletPath(HttpServletRequest request) {
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://" + request.getServerName()
		+ ":" + request.getServerPort() + path + request.getServletPath() + "?";
		return basePath;
	}
	
	/**
	 * 获取路径URL
	 * @param request
	 * @return
	 */
	protected String getRequestURI(HttpServletRequest request) {
		String basePath = request.getScheme() + "://" + request.getServerName()
		+ ":" + request.getServerPort() + request.getRequestURI() + "?";
		return basePath;
	}
}
